﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MLSharp.Utilities
{
	/// <summary>
	/// Provides utility methods for generating random names.  These
	/// can be useful for generating unique stems for See5 and other
	/// programs.
	/// </summary>
	public static class NameGenerator
	{
		#region Private Const Fields 

		/// <summary>
		/// Just a set of characters to use for generating names.
		/// </summary>
		const string mCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

		#endregion

		#region Read-Only Fields

		/// <summary>
		/// Used to select random characters.
		/// </summary>
		private static readonly Random mRand = new Random();

		#endregion

		#region Public Methods

		/// <summary>
		/// Generates a random string of the specified length.
		/// </summary>
		/// <param name="length"></param>
		/// <returns></returns>
		public static string GetRandomName(int length)
		{
			StringBuilder buffer = new StringBuilder(length);
			for (int i = 0; i < length; i++)
			{
				int randomNumber = mRand.Next(0, mCharacters.Length);
				buffer.Append(mCharacters, randomNumber, 1);
			}
			return buffer.ToString();
		}

		#endregion
	}
}
